package servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/servlet/login")
public class LoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        if ("admin".equals(username) && "123456".equals(password)) {
                //将用户信息保存session
            HttpSession session = request.getSession();
            session.setAttribute("fullName","爱编程");
            response.sendRedirect("../index.jsp");
        }else{
            request.setAttribute("msg","用户名或密码错误！");
            request.getRequestDispatcher("../login.jsp").forward(request,response);
        }
    }

}
